import Vue from 'vue'
import VueRouter from 'vue-router'
import store from './vuex/store'
import VueResource from 'vue-resource'

import router from './router'

import App from './components/App.vue'

import config from './api/config'
import service from './api/service'
import publics from './api/publics'
import util from './api/util'
import biz from './api/biz'
import fliter from './api/filter'


//全局注入
Vue.prototype.cfg = config;
Vue.prototype.service = service;
Vue.prototype.publics = publics;
Vue.prototype.util = util;
Vue.prototype.biz = biz;

Vue.config.devtools = true;

Vue.use(VueResource);
Vue.use(VueRouter);

//how to regist a config to global?



router.beforeEach((to, from, next) => {
    let user = sessionStorage.getItem("user");
    if (!user) {
        if (to.name !== 'macip' && to.name !== 'ad' && to.name !== 'login') {
            next({
                path: '/login'
            });
        } else {
            next();
        }
    }
    next();
});

router.afterEach((to, from,next) => {

});

window.router = router;
window.Vue = Vue;
Vue.http.options.emulateHTTP = true;
Vue.http.options.root = config.api;

new Vue({
    store,
    router,
    render: h => h(App),
}).$mount('#app');